class VideoController < ApplicationController
  def index
    Video.update_files
    @list = Video.find(:all).sort
  end

  def transcode
    video = Video.find(params[:id])
    Operation.create :video => video, :operation => 'transcode' 
    render :text => "queued"
  end

  def delete
    @video = Video.find(params[:id])
    @video.delete
  end

  def download
    @video = Video.find(params[:id])
    if !Video.check_iphone
      flash[:error] = "iPhone is unaccessable"
    else
      Operation.create :video => @video, :operation => 'download'
    end
  end

  def start_operations
    Operation.start
    render :text => 'ok'
  end

  def clear_operations
    Operation.destroy_all
  end

  def get_statuses
    @progress_list = Video.find_all_by_status('progress')
    @finished_list = Video.find_all_by_status('converted')
  end
end
